<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="resource/my97date/WdatePicker.js"></script>
    <link rel="stylesheet" href="resource/css/bootstrap.css">
    <script type="text/javascript" src="resource/js/jquery-3.2.1.js"></script>
    <script src="resource/js/bootstrap.js"></script>
    <title></title>
</head>
<body>
<form:form method="post" action="add" modelAttribute="goods">
    收货单号<form:input path="gnumber"/>
    收货日期<form:input path="stime" type="date"/><br>
    制单人<select name="uid">
            <option value="">--请选择--</option>
        </select>
    状态<select name="zid">
            <option value="">--请选择--</option>
        </select>
    优先级<select name="yid">
            <option value="">--请选择--</option>
        </select><br>
    客户<form:input path="client"/>
    制单时间<form:input path="ztime" type="date"/><br>
    收货附件<input type="file" name="file" onchange="upFile(this)">
    客户发货单列表<form:input path="khfsid"/><br>
    备注:<form:textarea path="remark" />
    <button type="submit">提交</button>
</form:form>
<script>
    var uid =${user.id}
    var role=${user.role}
    uid--;


    function upFile(obj) {
        var formData = new FormData();
        formData.append("file",obj.files[0]);
        $.ajax({
            type:"post",
            url:"upFile",
            date:formData,
            contentType:false,
            prototype:false,
            success:function(msg){
            $("[name='pic']").html("");
            $("[name='pic']").append('<img src="'+msg+'" width="200px" height="150px">');
            $("[name='pic']").append('<input type="text" name="picture" value="'+msg+'">');
            }
        })
    }

    $.post("listz",function (obj) {
        for (var i in obj) {
            $("[name='zid']").append('<option value="'+obj[i].id+'">'+obj[i].zname+'</option>')
        }
    })
    $.post("listy",function (obj) {
        for (var i in obj) {
            $("[name='yid']").append('<option value="'+obj[i].id+'">'+obj[i].yname+'</option>')
        }
    })
    $.post("listu",function (obj) {

            if (role!=1){
                    $("[name='uid']").append('<option value="'+obj[uid].id+'">'+obj[uid].unumber+'-'+obj[uid].uname+'</option>')

            }else{
                for (var i in obj) {
                    $("[name='uid']").append('<option value="'+obj[i].id+'">'+obj[i].unumber+'-'+obj[i].uname+'</option>')
                }
            }


    })
</script>

</body>
</html>